/**
 * $Revision$
 * $Date$
 *
 * This file is part of the Solveur repository software.
 * Copyright (C) 2012 Solveur developer team
 * See http://code.google.com/p/solveur/
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 **/

package gougeon.android.solveur;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Handler;
import android.os.Message;

public class MonHandler extends Handler {

	private final Activity activity;

	ProgressDialog progressDialog;
	ProgressDialog progressDialog2;
	ProgressDialog progressDialog3;
	
	int recherche_progres;
	
	public MonHandler(Activity activity) {
		this.activity = activity;
		progressDialog = new ProgressDialog(this.activity);
		progressDialog2 = new ProgressDialog(this.activity);
		progressDialog3 = new ProgressDialog(this.activity);
	}
	
	public void handleMessage(Message msg) {
		
		switch (msg.what)
		{
			case 1:
				//Log.d("solveur.handler","Formatage en cours ... up to "+msg.arg1);
				progressDialog2.setMessage("Formatage en cours ...");
				progressDialog2.setTitle(""+msg.arg1+" résultat(s) trouvé(s) !");
				progressDialog2.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
				progressDialog2.setMax(msg.arg1);
				progressDialog2.show();
				break;
			case 3:
				//Log.d("solveur.handler","Mise à jour progression formatage  ...");
				progressDialog2.setProgress(msg.arg1);
				break;
			case 4:
				//Log.d("solveur.handler","Masquage dialogue de progression ...");
				progressDialog2.dismiss();
				break;

		
			case 91:
				//Log.d("solveur.handler","Recherche en cours ... up to "+msg.arg1);
				progressDialog3.setMessage("Recherche en cours ...");
				progressDialog3.setTitle("Au boulot !");
				recherche_progres=1;
				progressDialog3.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
				progressDialog3.setMax(msg.arg1);
				progressDialog3.show();
				break;				
			case 92:
				//Log.d("solveur.handler","Mise à jour progression recherche  ..."+recherche_progres);
				progressDialog3.setProgress(recherche_progres++);
				break;
			case 93:
				//Log.d("solveur.handler","Masquage dialogue de progression ...");
				progressDialog3.dismiss();
				break;


			case 101:
				//Log.d("solveur.handler","Recherche en cours ...");
				progressDialog.setMessage("Chargement des dictionnaires en cours ...");
				progressDialog.setTitle("Patientez ...");
				recherche_progres=1;
				progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
				progressDialog.setMax(msg.arg1);
				progressDialog.show();
				break;
			case 102:
				//Log.d("solveur.handler","Mise à jour chargement dico  ..."+msg.arg1);
				progressDialog.setProgress(recherche_progres++);
				break;
			case 103:
				//Log.d("solveur.handler","Fermeture dialogue de progression ...");
				progressDialog.dismiss();
				break;

		
			default:
				break;
		}
	};
	
}
